package top.frsf.card;

import java.awt.*;
import java.time.Duration;
import java.time.Instant;

/**
 * @BelongsProject: MiniPZ
 * @BelongsPackage: top.frsf.card
 * @Author: FRSF
 * @CreateTime: 2022-09-08  23:51
 * @Description: 豌豆卡片
 * @Version: 1.0
 */
public class PeaseCard extends CardObject {

    public PeaseCard(String img, String darkImage, String moveImage, int x, int y, int width, int height, long cd, int price) {
        super(img, darkImage, moveImage, x, y, width, height, cd, price);
    }

    @Override
    public void paintSelf(Graphics g) {
        super.paintSelf(g);
        if (movePoint != null) {
            g.drawImage(moveImage, movePoint.x - 35, movePoint.y - 35, null);
        }
        if (isCD) {
            // 处于冷却时间
            double seconds = Duration.between(click, Instant.now()).toMillis();

            // 若冷却未完成
            if (seconds < CD) {
                int h = (int) ((seconds / CD) * getHeight());
                g.drawImage(darkImage, getX(), getY(), getX() + getWidth(), getY() + h,
                        0, 0, getWidth(), h, null);
            } else {
                isCD = false;
            }
        }
    }
}
